class ConeheadZombie extends GuaAnimation {
    static new(game, name) {
        let z = new this(game, animationConeheadZombie, name)
        z.setup()
        return z
    }

    setup() {
        // row表示在草地的第几排
        this.row = -1
        this.column = -1
        this.hp = 5
        this.zombie_speed = 1
        this.eat = 5
        this.ready = false
        this.death = false
        this.goback = false
        this.lost = false
        this.boom = false
        this.flipX = false
    }


    debug() {
        this.zombie_speed = config.zombie_speed.value
    }

    beattack(damage) {
        this.hp -= damage
        if (this.death) {
            this.die()
        }
        if (this.hp < 1) {
            // this.scene.removeHead(this)

            this.death = true
        }

    }


    walk() {
        log('walking')
        this.changeAnimation('walking')
    }

    attacking() {
        this.changeAnimation('attack')
        this.x += this.zombie_speed
    }

    attack() {
        this.attacking()
        this.eat--
        log('this.eat', this.eat)
        if (this.eat === 0) {
            this.goback = true
            this.flipX = true
        }
    }

    remove() {
        this.scene.removeZombie(this)
    }

    iced() {
        this.zombie_speed = 0.5
    }

    Gralicd() {
        this.row = randomBetween(0, 4)
        this.y = this.game.scene.zombieoffsetY + this.row * this.game.scene.heightOfRow
    }

    spiked() {
        this.hp--
        this.zombie_speed = 0.7
        if (this.hp === 0) {
            this.die()
        }
    }

    die() {
        // 播放死亡动画
        // this.changeAnimation('die')
        //删除僵尸
        this.remove()

    }

    boomdie() {
        // 播放死亡动画
        this.changeAnimation('boomdie')
        //删除僵尸
        this.scene.removeZombie(this)
        // this.scene.numOfZombie -= 1
    }

    back() {
        if (this.goback) {
            this.walk()
            this.x += this.zombie_speed * 2
            if (this.x === 1200) {
                this.goback = false
                this.flipX = false
            }
        }

    }

    changestatus() {
        let self = this

        if (this.lost) {
            this.scene.removeHead(self)
        }
        if (this.ready) {
            this.x -= this.zombie_speed
            // if (this.hp === 2) {
            //     this.changeAnimation('lost_head')
            // }
            // if (this.death) {
            //     this.changeAnimation('die')
            // }
        }

    }


    update() {
        super.update()
        this.back()
        this.changestatus()

    }

}